package com.surprise.cweb.manager;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.surprise.cweb.APIConstants;
import com.surprise.db.entity.BUser;

/**
 * SessionManager.java
 * @author nick
 * @since 2015年7月20日
 */
@Component
public class SessionManager {
	public HttpServletRequest getRequest() {
		return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
	}
	
	public BUser getCurrentUser() {
		return (BUser)getRequest().getSession().getAttribute(APIConstants.USER);
	}
	
	public void setUser(BUser user) {
		getRequest().getSession().setAttribute(APIConstants.USER, user);
	}
}
